<?php
header('Content-type:text/html;charset=utf-8');//设置编码格式
session_start();
include_once 'dbconfig.php';
include_once 'common.php';


if ($_POST) {
    if (isset($_POST['postType']) && $_POST['postType'] == 'addone') {
        shopCartEvent();
    } else if (isset($_POST['postType']) && $_POST['postType'] == 'changeNum') {
        $id = $_POST['id'];
        $num = $_POST['num'];
        $updateStr = 'update shop_cart set num=' . $num . ' where id=' . $id;
        if ($link->query($updateStr) === true) {
            $msg = ['msg' => '修改成功。', 'status' => 1];
        } else {
            $msg = ['msg' => '修改失败。', 'status' => 0];
        }
        responseEvent($msg);
    }
}

if ($_GET) {
    if (isset($_GET['getType']) && $_GET['getType'] == 'getShopCartList') {
        if (isset($_SESSION['loginUserName'])) {
            $name = $_SESSION['loginUserName'];
        } else {
            $msg = ['msg' => '请先登录！', 'status' => 0];
            responseEvent($msg);
        }
        $selectShopCartList = 'select a.num,a.color as scolor,a.id as shopId,b.* from shop_cart as a JOIN product as b on a.pro_id=b.id where a.username="' . $name . '" and a.status=1';
        $res = $link->query($selectShopCartList);
        if ($res->num_rows > 0) {
            $arr = [];
            while ($row = $res->fetch_assoc()) {
                array_push($arr, $row);
            }
            responseEvent($arr);
        }
    }
}

